package edu.neusoft.android.yuejian14.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import java.util.List;

import edu.neusoft.android.yuejian14.Listener.RetrofitListener;
import edu.neusoft.android.yuejian14.R;
import edu.neusoft.android.yuejian14.adapter.CourseListAdapter;
import edu.neusoft.android.yuejian14.javabean.Course;
import edu.neusoft.android.yuejian14.model.CourseModel;

public class CourseListActivity extends BaseActivity implements View.OnClickListener,RetrofitListener {
    private RecyclerView recyclerView;
    private List datalist;
    private TextView club_name,club_intro,club_video;
    private CourseListAdapter courseListAdapter;
    private int clubid;
    private String clubName;


    @Override
    protected void initViews(){
        setLayout(R.layout.club_course_list);

        recyclerView =(RecyclerView)findViewById(R.id.home_recycler);
        club_name=(TextView) findViewById(R.id.cl_name);
        club_intro =(TextView) findViewById(R.id.cl_intro);
        club_intro.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(CourseListActivity.this,ClubIntroActivity.class);
                Bundle bundle= getIntent().getExtras();
                clubid=bundle.getInt("clubid");
                intent.putExtra("clubid",clubid);
                startActivity(intent);

            }
        });
        club_video =(TextView) findViewById(R.id.cl_video);
        club_video.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(CourseListActivity.this,VideoListActivity.class);
                Bundle bundle= getIntent().getExtras();
                clubid=bundle.getInt("clubid");
                intent.putExtra("clubid",clubid);
                startActivity(intent);
            }
        });
    }

    @Override
    View initViews(View view) {
        return null;
    }

    @Override
    void initEvents() {
        clubid = getIntent().getIntExtra("clubid",-1);
        clubName = getIntent().getStringExtra("clubname");
        club_name.setText(clubName);
    }

    @Override
    public void initData(){

        CourseModel courseModel = new CourseModel();
        courseModel.getcourselistByClubId(String.valueOf(clubid),this);

    }




    @Override
    public void onSuccess(Object object, int flag) {
        List<Course> course = (List<Course>) object;
        courseListAdapter = new CourseListAdapter(CourseListActivity.this,course);
        LinearLayoutManager layoutManager = new LinearLayoutManager(CourseListActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(courseListAdapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void onFail() {

    }

    @Override
    public void onClick(View view) {

    }
}